import Vue from 'vue'
import Vuex from 'vuex'
import '../main'

Vue.use(Vuex);

const store = new Vuex.Store({
    state: {
        isLogin: false,
        isContinue: false,
        question: {},
        surveyToAnalyze: {}, // 用于保存report页面的问卷数据
    },
    mutations: {
        login(state) {
            state.isLogin = true;
            var user = {
                username: window.sessionStorage.getItem("username"),
                uid: window.sessionStorage.getItem('uid')
            }
            localStorage.setItem("LoginState", JSON.stringify(user));
        },
        logout(state) {
            state.isLogin = false
            localStorage.removeItem("LoginState")
        },
        initLog(state) {
            var s = localStorage.getItem("LoginState");
            if (s !== null) {
                var user = JSON.parse(s)
                window.sessionStorage.setItem("username", user.username);
                window.sessionStorage.setItem('uid', user.uid)
                state.isLogin = true;
            }
        },
        continue(state, question) {
            state.question = question
            console.log(question);
            state.isContinue = true
        },
        saveSurveyAnalysis(state, surveyToAnalyze) {
            state.surveyToAnalyze = surveyToAnalyze
        }
    }
})


export default store